<?php
namespace Modules\Code\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Modules\Code\Entities\CodeRecord;

use Validator;
use ThrowException;
use Auth;

class CodeRecordController extends Controller
{
    public function index(Request $req)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $options = $req->all();

        $user = Auth::requireLoginUser();

        // $options['order_by'] = ['list_weight' => 'desc'];
        $options['with'] = ['code.coupon', 'code.chip'];
        $options['where']['user_id'] = $user->id;

        $options['builder'] = CodeRecord::whereHas('code');

        $list = CodeRecord::getList($options);

        return $list->generateListResponse();
    }
}
